<template>

  <el-form :inline="true" :model="searchData" class="demo-form-inline">
    <el-form-item label="专业类别">
      <el-cascader
          v-model="major"
          :options="options"
          :props="props"
          placeholder="请选择"
          @change="handleChange"></el-cascader>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="onSubmit">查询</el-button>
    </el-form-item>
  </el-form>
  <el-table
      :data="tableData"
      border
      v-loading="loading"
      style="width: 100%">
    <el-table-column
        prop="majorCat"
        label="专业类别"
        width="400px">
    </el-table-column>
    <el-table-column
        prop="majorName"
        label="专业名称"
        width="400px">
    </el-table-column>
    <el-table-column
        prop="majorCode"
        label="专业编号"
        width="400px">
    </el-table-column>
    <el-table-column
        prop="majorSat"
        label="满意度">
    </el-table-column>
  </el-table>

</template>

<script>
import {onBeforeMount, reactive, toRefs} from "vue";
import {options, pages} from "@/api/majorLib";

export default {
  name: "index",
  setup(){

    const data = reactive({
      loading: false,
      props: { expandTrigger: 'hover' },
      tableData: [],
      major: '',
      searchData: {
        majorType: '本科（普通教育）',
        category: '哲学',
      },
      options: [],
      allAddress: [],
      allColType: []
    })

    const onSubmit = () => {
      data.loading = true
      pages(data.searchData).then(res => {
        data.tableData = res.data
        data.loading = false
      })
    }

    const handleChange = (value) => {
      data.searchData.majorType = value[0]
      data.searchData.category = value[1]
    };
    onBeforeMount(() => {
      options().then(res => {
        data.options = res.data
      })

      data.loading = true
      pages(data.searchData).then(res => {
        data.tableData = res.data
        data.loading = false
      })
    })

    return {
      ...toRefs(data),
      onSubmit,
      handleChange
    }
  }
}
</script>

<style scoped>

</style>
